package com.rabbithelper.listener;

import com.rabbithelper.handle.MessageHandler;
import com.rabbithelper.handle.SycnHandler;
import com.rabbitmq.client.Channel;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.Header;

/**
 * @program: waterx
 * @description: 用户信息同步
 * @author: qinghuan
 * @create: 2024-09-24 14:59
 **/
@AllArgsConstructor
@Configuration
public class PubSyncListener extends MessageHandler {

    private final SycnHandler sycnHandler;

    /**
     * 用户信息处理
     *
     * @param messageBody 用户数组
     */
    @RabbitListener(queues = "${client.queues}" + "_user")
    public void receiveUserInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleUserInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 岗位信息处理
     *
     * @param messageBody 岗位数组
     */
    @RabbitListener(queues = "${client.queues}" + "_post")
    public void receivePostInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handlePostInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 角色信息处理
     *
     * @param messageBody 角色数组
     */
    @RabbitListener(queues = "${client.queues}" + "_role")
    public void receiveRoleInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleRoleInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 菜单信息处理
     *
     * @param messageBody 菜单数组
     */
    @RabbitListener(queues = "${client.queues}" + "_menu")
    public void receiveMenuInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleMenuInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 部门信息处理
     *
     * @param messageBody 部门数组
     */
    @RabbitListener(queues = "${client.queues}" + "_dept")
    public void receiveDeptInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleDeptInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 用户角色关联信息处理
     * @param messageBody 用户角色关联数组
     */
    @RabbitListener(queues = "${client.queues}" + "_user_role")
    public void receiveUserRoleInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleUserRoleInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 用户岗位关联信息处理
     * @param messageBody 用户岗位关联数组
     */
    @RabbitListener(queues = "${client.queues}" + "_user_post")
    public void receiveUserPostInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleUserPostInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 用户部门关联信息处理
     * @param messageBody
     */
    @RabbitListener(queues = "${client.queues}" + "_user_dept")
    public void receiveUserDeptInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleUserDeptInfo(messageBody, deliveryTag, channel);
    }

    /**
     * 角色菜单关联信息处理
     * @param messageBody
     */
    @RabbitListener(queues = "${client.queues}" + "_role_menu")
    public void receiveRoleMenuInfo(String messageBody, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel){
        handleRoleMenuInfo(messageBody, deliveryTag, channel);
    }

}
